#include "mstyle.h"

MStyle::MStyle(QString style):ori_style(style)
{
    if(!ori_style.length()){
        return;
    }
    style_list = ori_style.split(";");
    QStringListIterator striter(style_list);
    while (striter.hasNext()){
       QString tmp = striter.next();
       int split_post = tmp.indexOf(":");
       if (!tmp.length()||!split_post){
           continue;
       }
       QString key = tmp.left(split_post);
       QString val = tmp.right(tmp.length() -  split_post - 1);
       m_map[key] = val;
    }
}

void MStyle::SetStyle(QString key, QString text)
{
    m_map[key] = text;
}

QString MStyle::GetStyle()
{
    new_style = "";
    QMap<QString, QString>::const_iterator map_iter = m_map.constBegin();
    while(map_iter != m_map.constEnd()){
        new_style.append(map_iter.key());
        new_style.append(":");
        new_style.append(map_iter.value());
        new_style.append(";");
        ++map_iter;
    }
    return new_style;
}
